package de.lehrbaum.outlokker.start;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.FrameLayout;
import de.lehrbaum.outlokker.R;
import de.lehrbaum.outlokker.start.StartSurface.PART;

/**
 * The starting activity.
 * @author Ulic Quel-droma
 * @version 1.0
 */
public class StartActivity extends Activity implements StartSurface.OnPartClickListener {
	private StartSurface surface;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_start);
		getActionBar().setDisplayHomeAsUpEnabled(true);
	}
	
	@Override
	protected void onStart() {
		FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
		surface = new StartSurface(getApplicationContext(), this);
		frame.addView(surface);
		super.onStart();
	}
	
	@Override
	protected void onStop() {
		FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
		frame.removeView(surface);
		super.onStop();
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		/* Saves memory and time. The surface looks the same always anyway. */
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_start, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	@Override
	public void onPartClick(PART partClicked) {
		// TODO open the right activity and start the animation.
	}
}